<?php
namespace app\common\subscribe;
use think\facade\Cache;
use app\common\service\Redis;
class Subscribe
{
    protected $ip = '47.114.152.142';
    protected $port = '6379';
    protected $password = 'baguatan';

    /*
     * 开启订阅
     * 命令行调用 php index.php admin/subscribe/psubscribe
     */
    public function psubscribe(){
        $redis = new \Redis();
        $redis->connect($this->ip,$this->port);
        $redis->auth($this->password);
        //解决Redis客户端订阅时候超时情况
        $redis->setOption(\Redis::OPT_READ_TIMEOUT, -1);
        $redis->psubscribe(array('__keyevent@0__:expired'), 'keyCallback');
    }
    /*
     * 设置过期redis值 用 - 分隔，可以获得设置的信息
     */
    public function setRedis(){
        $order = 'orderId-1001011-db-admin-filed-ad_id';
        $redis = Cache::handler();

        if($redis->get($order)){
            dump($redis->get($order));
        }else{
            dump($redis->setex($order, 100, 'redis'));
        }
    }
}